const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    slowMo: 100,    //放慢速度
    headless: false,
    defaultViewport: {width: 800, height: 600},
    ignoreHTTPSErrors: false, //忽略 https 报错
    args: ['--start-fullscreen'] //全屏打开页面
  });
  const page = await browser.newPage();
  await page.goto('https://gitee.com/login');
  //输入账号密码
  const uniqueIdElement = await page.$('#user_login');
  await uniqueIdElement.type('Kaylaee', {delay: 20});
  const passwordElement = await page.$('#user_password', {delay: 20});
  await passwordElement.type('gitlab11x');
  //点击确定按钮进行登录
  let okButtonElement = await page.$('.submit');
  //等待页面跳转完成，一般点击某个按钮需要跳转时，都需要等待 page.waitForNavigation() 执行完毕才表示跳转成功
  await Promise.all([
    okButtonElement.click(),
    page.waitForNavigation()
  ]);
  console.log('admin 登录成功');
  // await page.close();
  // await browser.close();
})();
